<div class="dux-page-header uk-clearfix">
    <div class="page-title">
        <a class="uk-button uk-button-primary" href="{url('index')}"> 返回列表</a>
    </div>
    <div class="page-action">
        <a class="uk-button uk-button-danger" href="javascript:location.reload();"><i class="fa fa-refresh"></i></a>
    </div>
</div>

<div class="uk-margin-top">
    <div class="uk-card uk-card-default uk-card-small dux-panel">
        <div class="uk-card-header">{$assignName}优惠券</div>
        <div class="uk-card-body">
            <form class="dux-form uk-form   uk-form-horizontal " data-dux="form-bind" method="post">
                <fieldset>

                    <div class="uk-form-group">
                        <label class=" uk-form-label">优惠券描述</label>
                        <div class="uk-form-controls">
                            <input type="text" name="name" value="{$info.name}" placeholder="请输入优惠券描述" required>
                        </div>
                    </div>

                    <div class="uk-form-group">
                        <label class=" uk-form-label">优惠券类型</label>
                        <div class="uk-form-controls uk-form-controls-text ">
                            <div class="uk-grid">
                                <!--loop{$typeList as $type => $vo}-->
                                <label>
                                    <input type="radio" name="type" value="{$type}" data-type="{$vo.type}" {$type == $info.type ? 'checked' : ''}> {$vo.name}
                                </label>
                                <!--{/loop}-->
                            </div>
                        </div>
                    </div>

                    <div class="uk-form-group">
                        <label class=" uk-form-label">优惠券分类</label>
                        <div class="uk-form-controls">
                            <select name="class_id">
                                <!--loop{$classList as $vo}-->
                                <option value="{$vo.class_id}"  {$vo.class_id == $info.class_id ? 'selected' : ''}>{$vo.name}</option>
                                <!--{/loop}-->
                            </select>
                        </div>
                    </div>

                    <div class="uk-form-group">
                        <label class=" uk-form-label">封面图</label>
                        <div class="uk-form-controls">
                            <div class="uk-input-group">
                                <input class="uk-form-field" type="text" name="image" id="image" value="{$info.image}" placeholder="优惠券封面图">
                                <span class="uk-input-group-btn">
                                            <button class="uk-button uk-button-default" type="button" data-dux="form-upload"
                                                    data-target="#image" data-type="jpg,png,bmp"
                                                    data-callback="imageUpload"><i
                                                    class="fa fa-upload"></i></button>
                                        </span>
                            </div>
                        </div>
                    </div>


                    <div id="type-body"></div>




                    <div class="uk-form-group">
                        <label class=" uk-form-label">优惠券金额</label>
                        <div class="uk-form-controls">
                            <input type="text" name="money" value="{$info.money}" placeholder="请输入优惠券金额" required>
                        </div>
                    </div>
                    <div class="uk-form-group">
                        <label class=" uk-form-label">满减金额</label>
                        <div class="uk-form-controls">
                            <input type="text" name="meet_money" value="{$info.meet_money ? $info.meet_money : 0}" placeholder="满足使用金额条件" required>
                        </div>
                    </div>
                    <div class="uk-form-group">
                        <label class=" uk-form-label">发放时间</label>
                        <div class="uk-form-controls">
                            <input type="text" data-dux="form-date" name="start_time" data-type="datetime" value="{$info.start_time ? date('Y-m-d H:i:s', $info.start_time) : date('Y-m-d H:i:s')}" required>
                        </div>
                    </div>
                    <div class="uk-form-group">
                        <label class=" uk-form-label">结束时间</label>
                        <div class="uk-form-controls">
                            <input type="text" data-dux="form-date" name="end_time" data-type="datetime" value="{$info.end_time ? date('Y-m-d H:i:s', $info.end_time) : date('Y-m-d H:i:s', strtotime('+1 month'))}" required>
                        </div>
                    </div>
                    <div class="uk-form-group">
                        <label class=" uk-form-label">库存数量</label>
                        <div class="uk-form-controls">
                            <input type="text" name="stock" value="{$info.stock ? $info.stock : 100}" placeholder="" required>
                        </div>
                    </div>
                    <div class="uk-form-group">
                        <label class=" uk-form-label">有效天数</label>
                        <div class="uk-form-controls">
                            <input type="number" name="expiry_day" value="{$info.expiry_day ? $info.expiry_day : 10}" placeholder="" required>
                        </div>
                    </div>

                    <div class="uk-form-group">
                        <div class="uk-form-controls">
                            <input type="hidden" name="coupon_id" value="{$info.coupon_id}">
                            <button class="uk-button uk-button-primary" type="submit" disabled>保存</button>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>
<script type="text/html" id="class-tpl">
    <div class="uk-form-group type-item">
        <label class=" uk-form-label">类目选择</label>
        <div class="uk-form-controls">
            <select data-dux="form-select" name="has_id" required style="width: 100%">
                <!--loop{(array)$goodsClass as $vo}-->
                <option <!--if{$vo.class_id == $info.has_id}--> selected <!--{/if}-->
                value="{$vo.class_id}">{$vo.cname}</option>
                <!--{/loop}-->
            </select>
            <div class="uk-form-help">选择顶级分类将自动对子分类产品生效</div>
        </div>
    </div>
</script>

<script type="text/html" id="goods-tpl">
    <div class="uk-form-group type-item">
        <label class=" uk-form-label">商品选择</label>
        <div class="uk-form-controls">
            <div class="">
                <table class="uk-table  uk-table-responsive  uk-table-striped uk-table-hover uk-table-middle dux-table dux-table-dialog uk-text-nowrap" style="border: 1px solid #ddd">
                    <thead>
                    <tr>
                        <th>
                            <button class="uk-button uk-button-primary" type="button" id="add-has">增加商品选择</button>
                        </th>
                    </tr>
                    </thead>
                    <tbody  id="has-list">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="tpl">
    <tr>
        <td>
            <select data-dux="form-select" name="has_id[]">
                <option value="0">==请选择商品==</option>
                <!--loop{(array)$mallList as $vo}-->
                <option value="{$vo.mall_id}">{$vo.title}</option>
                <!--{/loop}-->
            </select>
        </td>
    </tr>
</script>

<script>
    Do('base', function () {
        var layout = $('#type-body');
        layout.on('click', '#add-has', function () {
            addHas();
        });
        var addHas = function () {
            var html = $('#tpl').html();
            layout.find('#has-list').append(html);
            var $el = layout.find('#has-list').find('tr:last').find("[data-dux='form-select']");
            form.select($el, $el.data());
        };

        $('input[name="type"]').change(function () {
            change();
        });
        var change = function () {
            var type = $('input[name="type"]:checked').data('type');
            layout.html('');
            if(type == 1) {
                layout.html($('#goods-tpl').html());
            }
            if(type == 2) {
                layout.html($('#class-tpl').html());
            }
            var $el = layout.find("[data-dux='form-select']");
            form.select($el, $el.data());
        };
        change();
    });
</script>